<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="heaerTopContent">
        <div class="grid-content bg-purple">
          <!-- <el-input v-model.trim="listQuery.createUserName" placeholder="" style="width: 350px;" class="filter-item" @keyup.enter.native="handleFilter" /> -->
          <el-input v-model="listQuery.searchString" placeholder="请输入搜索内容" clearable style="width: 300px;" class="filter-item" @keyup.enter.native="handleFilter" />
          <el-button class="filter-item" type="danger" style="margin-left: 10px;" icon="el-icon-search" @click="handleFilter">
            搜索
          </el-button>
        </div>
        <div class="grid-content bg-purple">
          <el-button style="margin-left: 10px;" type="info" icon="el-icon-download" @click="downloadExcel">收货模板下载</el-button>
        </div>
        <div class="grid-content bg-purple-light">
          <el-upload
            ref="upload"
            class="uploadExcel"
            style="margin-left:10px"
            action=""
            accept=".xlsx"
            :limit="limitNum"
            :auto-upload="false"
            :show-file-list="false"
            :on-change="uploadChange"
          >
            <el-button type="success" icon="el-icon-circle-plus-outline">上传收货信息</el-button>
          </el-upload>
        </div>
      </div>
    </div>
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      element-loading-text="拼命加载中"
      :data="tableData"
      :default-sort="{prop:'createTime',order:'descending'}"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column label="序号" type="index" align="center" width="100">
        <template slot-scope="scope">
          <span>{{ (listQuery.pageNo-1)*listQuery.pageSize+scope.$index +1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收件人" class-name="status-col" width="120" align="center">
        <template slot-scope="{row}">
          {{ row.recipient }}
        </template>
      </el-table-column>
      <el-table-column label="电话地址" class-name="status-col" align="center">
        <template slot-scope="{row}">
          {{ row.recipientInformation }}
        </template>
      </el-table-column>
      <el-table-column label="快递单号" class-name="status-col" width="200" align="center">
        <template slot-scope="{row}">
          {{ row.trackingNumber }}
        </template>
      </el-table-column>
      <el-table-column label="商品信息" prop="goodsInformation" class-name="status-col" align="center">
        <template slot-scope="{row}">
          {{ row.goodsInformation }}
        </template>
      </el-table-column>
      <el-table-column label="发货时间" width="180" prop="createTime" sortable align="center">
        <template slot-scope="{row}">
          <span>{{ row.createTime }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作人" prop="createUserName" sortable="custom" align="center" width="150">
        <template slot-scope="{row}">
          <span>{{ row.createUserName }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="Actions" align="center" class-name="small-padding fixed-width">
          <template slot-scope="{row}">
            <el-button type="primary" size="mini" @click="handleUpdate(row)">
              详情
            </el-button>
          </template>
        </el-table-column> -->
    </el-table>
    <!-- 页码 -->
    <div class="pageGation">
      <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNo" :limit.sync="listQuery.pageSize" @pagination="getDeliveAllList" />
    </div>

  </div>
</template>

<script>
// import parseTime from '@/utils/index'
import { addDeliver, getDeliverList } from '@/api/delivergoods'
import Pagination from '@/components/Pagination'
import axios from 'axios'
export default {
  components: {
    Pagination
  },
  data() {
    return {
      titleName: '入库',
      tableData: [],
      currentRow: null,
      tableKey: 0,
      fileList: [],
      limitNum: 1, // 上传个数
      total: 0,
      optionsUser: null,
      listQuery: {
        searchString: '',
        pageNo: 1,
        pageSize: 20
      },
      listLoading: false
    }
  },
  created() {
    this.getDeliveAllList()
    // this.getUserIdSelect()
  },
  methods: {
    // 获取入库列表
    getDeliveAllList() {
      this.listLoading = true
      getDeliverList(this.listQuery).then(res => {
        if (res.code === '00000') {
          this.listLoading = false
          this.total = res.data.totalRows
          this.tableData = res.data.rows
        } else {
          this.$message.error('请求失败')
          this.listLoading = false
        }
      })
    },
    // 卡模板下载
    downloadExcel() {
      axios.get('static/shouhuoInfo.xlsx', {
        responseType: 'blob'
      }).then(response => {
        const url = window.URL.createObjectURL(new Blob([response.data]))
        const link = document.createElement('a')
        const fname = '收货excel模板.xlsx'
        link.href = url
        link.setAttribute('download', fname)
        document.body.appendChild(link)
        link.click()
      })
    },
    // 获取用户下拉id
    // async getUserIdSelect() {
    //   await getUserId().then(res => {
    //     if (res.code === '00000') {
    //       this.optionsUser = res.data
    //     }
    //   })
    // },
    // 搜索
    handleFilter() {
      this.loading = true
      setTimeout(() => {
        this.loading = false
        this.getDeliveAllList()
      }, 200)
    },
    // 入库
    uploadChange(item) {
      const formData = new FormData()
      const file = item.raw
      formData.append('file', file)
      // 请求
      this.listLoading = true
      addDeliver(formData).then(res => {
        if (res.code === '00000') {
          this.$message({
            message: '入库成功',
            type: 'success'
          })
          this.listLoading = false
          this.listQuery.searchString = ''
          this.getDeliveAllList()
        } else {
          this.$message.error('入库失败')
          this.listLoading = false
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.el-table{
  position: relative;
    overflow: hidden;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    -webkit-box-flex: 1;
    -ms-flex: 1;
    flex: 1;
    width: 100%;
    max-width: 100%;
    background-color: #fff;
    font-size: 14px;
    color: #606266;
}
.small-padding .cell {
    padding-left: 5px;
    padding-right: 5px;
}
.el-table .cell {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
    word-break: break-all;
    line-height: 23px;
    padding-left: 10px;
    padding-right: 10px;
}
.heaerTopContent{
  height: 100%;
  clear: both;
  .grid-content{
    float: left;
  }
}
.pageGation{
  display: flex;
  justify-content: flex-end;
  margin: 15px 40px 0;
  font-size: 23px;
}

</style>
